package whu.hami.tea.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import whu.hami.tea.R;
import whu.hami.tea.adapter.MainAdapter;
import whu.hami.tea.domain.Topic;

public class MainActivity extends AppCompatActivity {

    private TextView tvMessage, tvPublish, tvMine;
    private ListView listView;

    private MainAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView = (ListView) findViewById(R.id.lv_topic);

        tvMessage = (TextView) findViewById(R.id.tv_message);
        tvMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ChatActivity.class);
                startActivity(intent);
            }
        });
        tvPublish = (TextView) findViewById(R.id.tv_publish);
        tvPublish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, PublishActivity.class);
                startActivity(intent);
            }
        });
        tvMine = (TextView) findViewById(R.id.tv_mine);

        adapter = new MainAdapter(this, fakeData());
        listView.setAdapter(adapter);
    }

    private List<Topic> fakeData() {
        List<Topic> topics = new ArrayList<>();
        for (int i = 0; i < 10; i++){
            Topic topic = new Topic();
            topic.topic = "#话题" + i;
            topic.brief = "\t测试数据测试数据测试数据，测试数据测试数据测试数据，测试数据测试数据测试数据，" +
                    "测试数据测试数据测试数据，测试数据测试数据测试数据，测试数据测试数据测试数据，测试数据测试数据测试数据．";
            topics.add(topic);
        }
        return topics;
    }

    @Override
    public void onBackPressed() {
        finish();
    }
}
